package com.hzpjxld.ssh.guoshui.action;

import com.hzpjxld.ssh.guoshui.model.Person;
import com.hzpjxld.ssh.guoshui.service.TestService;
import com.opensymphony.xwork2.ActionSupport;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.annotation.Resource;

/**
 * Created by Administrator on 2018-04-20.
 */
public class TestAction extends ActionSupport {

    @Resource
    TestService testService;
    @Resource
    SessionFactory sf;

   /* public void setTestService(TestService testService){
         this.testService = testService;

    }*/

    //默认方法
    public String execute(){
       // ctx=new ClassPathXmlApplicationContext("classpath:spring/applicationContext.xml");

      //  SessionFactory sf=(SessionFactory)ctx.getBean("sessionFactory");
        Session session=sf.openSession();
        Transaction transaction=session.beginTransaction();
        //保存人员
        session.save(new Person("人员1"));
        transaction.commit();
        session.close();
        testService.say();
        return SUCCESS;
    }
}
